<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('告警记录')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 住户资料
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="locationId" name="locationId" th:value="${location.locationId}">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>地址：</label>
                                <input type="text" id="locationName" name="locationName" th:value="${location.locationName}"/>
                            </li>

                            <li>
                                <label>设备id：</label>
                                <input type="text" name="eqId"/>
                            </li>
                            <li>
                                <label>告警方法：</label>
                                <input type="text" name="alarmMethod"/>
                            </li>
                            <li>
                                <label>设备类型：</label>
                                <select name="eqType">
                                    <option value="">所有</option>
                                    <option value="1">阀门</option>
                                    <option value="2">热表</option>
                                    <option value="3">采集器</option>
                                    <option value="4">室温采集器</option>
                                    <option value="5">其它</option>
                                </select>
                            </li>
                            <li>
                                <label>告警级别：</label>
                                <select name="alarmType">
                                    <option value="">所有</option>
                                    <option value="1">一级告警</option>
                                    <option value="2">二级告警</option>
                                    <option value="3">三级告警</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>告警时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <label>本次报警状态：</label>
                                <select id="status" name="status">
                                    <option value="1">启用</option>
                                    <option value="">所有</option>
                                    <option value="0">已忽略</option>
                                </select>
                            </li>
                            <li>
                                <label>持续报警状态：</label>
                                <select id="alarmStatus" name="alarmStatus">
                                    <option value="1">启用</option>
                                    <option value="">所有</option>
                                    <option value="0">已忽略</option>
                                </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="data:alarm:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var prefix = ctx + "data/alarm";
    var editFlag = [[${@permission.hasPermi('data:alarm:edit')}]];


    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        queryInfoList();
        queryLocationTree();
    });

    function queryInfoList() {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "告警记录",
            columns: [
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'location.locationName',
                    title: '安装地址'
                },
                {
                    field: 'locationId',
                    title: '地址id',
                    visible: false
                },
                {
                    field: 'eqType',
                    title: '设备类型',
                    formatter: function (value) {
                        if(value==1){
                            return '阀门';
                        }else if(value==2){
                            return '热表';
                        }else if(value==3){
                            return '采集器';
                        }else if(value==4){
                            return '室温采集器';
                        }else if(value==5){
                            return '其它';
                        }
                    }
                },
                {
                    field: 'alarmType',
                    title: '告警级别',
                    formatter: function (value) {
                        if (value==1) {
                            return '<span class="label label-danger">一级告警</span>';
                        }
                        else if (value==2) {
                            return '<span class="label label-warning">二级告警</span>';
                        }
                        else if (value==3){
                            return '<span class="label label-info">三级告警</span>';
                        }
                    }
                },
                {
                    field: 'alarmMethod',
                    title: '告警方法'
                },
                {
                    field: 'alarmCode',
                    title: '告警代码'
                },
                {
                    field: 'alarmMsg',
                    title: '告警描述'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '本次报警状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return locationUser(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '持续报警状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return locationAlarm(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '采集时间',
                    sortable: true
                } ,
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true
                }/*,
                {
                    field: 'updateBy',
                    title: '修改人',
                    sortable: true
                }*/


                    ]
        };
        $.table.init(options);
    }

    function queryLocationTree()
    {
        var url = ctx + "base/location/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#locationId").val(treeNode.id);
            $.table.search();
        }
    }
    /* 用户状态显示 */
    function locationUser(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }
    /* 用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要忽略本次报警吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
        })
    }

    /* 用户管理启用 */
    function enable(id) {
        $.modal.confirm("确认要启用本次报警吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
        })
    }

    /* 用户状态显示 */
    function locationAlarm(row) {
        if (row.alarmStatus == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enablea(\'' + row.locationId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disablea(\'' + row.locationId + '\')"></i> ';
        }
    }
    /* 用户管理-停用 */
    function disablea(locationId) {
        $.modal.confirm("确认要停用用户报警吗？", function() {
            $.operate.post(ctx + "base/location/changeAlarmStatus", { "locationId": locationId, "alarmStatus": 0 });
        })
    }

    /* 用户管理启用 */
    function enablea(locationId) {
        $.modal.confirm("确认要启用用户报警吗？", function() {
            $.operate.post(ctx + "base/location/changeAlarmStatus", { "locationId": locationId, "alarmStatus": 1 });
        })
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryLocationTree();
    });
    /* 数据展示 */
    function detail(meterId) {
        // var meterId = $("#meterId").val();
        var url = ctx + 'report/meter/' + meterId;
        $.modal.openTab("热表数据展示", url);
    }
    /**
     * 热表数据采集
     */
    function check(){
        var locationId = $("#locationId").val();
        if(locationId==''){
            $.modal.alertWarning("请先选择采集地址");
            return;
        }
        $.operate.post(prefix + "/check", { "locationId": locationId });
    }
</script>
</body>
</html>